﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using h2sbk_sharp.DoNetExt;

namespace h2sbk_sharp.Controllers
{
    public class UDiskController : ApiController
    {
        [HttpGet, HttpPost]
        public HttpResponseMessage find ()
        {
            string rtv = null;
            try
            {
                var udisk = DriveInfo.GetDrives().Where(p => p.DriveType == DriveType.Removable).FirstOrDefault();
                if (udisk != null)
                {
                    if (File.Exists(udisk.RootDirectory + "export.txt"))
                    {
                        rtv = "ok";
                        return rtv.ToHttpResponseMessage();
                    }
                    else
                    {
                        return rtv.ToHttpResponseMessage();
                    }
                }
                else
                {
                    return rtv.ToHttpResponseMessage();
                }
            }
            catch
            {
                return rtv.ToHttpResponseMessage();
            }
        }

        [HttpGet, HttpPost]
        public HttpResponseMessage import ()
        {
            string rtv = null;
            try
            {
                var udisk = DriveInfo.GetDrives().Where(p => p.DriveType == DriveType.Removable).FirstOrDefault();
                if (udisk != null)
                {
                    string dstPath = udisk.RootDirectory + "export.txt";
                    if (File.Exists(dstPath))
                    {
                        string[] lines = File.ReadAllLines(dstPath);




                        rtv = "ok";
                        return rtv.ToHttpResponseMessage();
                    }
                    else
                    {
                        return rtv.ToHttpResponseMessage();
                    }
                }
                else
                {
                    return rtv.ToHttpResponseMessage();
                }
            }
            catch
            {
                return rtv.ToHttpResponseMessage();
            }
        }
    }
}
